<?php
/**
 * Created by PhpStorm.
 * User: zk
 * Date: 2018/9/27
 * Time: 上午10:22
 */

namespace app\models;
use yii\db\ActiveRecord;

class Pay_pay extends ActiveRecord {
    //获取充值列表
    //type  1支付宝 2 微信 0所有
    public function getRechargeLists($limit, $offset, $startTime, $endTime, $userName, $payType, $cityCode) {
        $post = Pay_pay::find()->joinWith('user')->where(['pay_pay.is_deleted' => 0, 'pay_pay.pay_status' => 1]);

        if ($startTime != -1) {
            $post->andWhere(['between', 'pay_pay.gmt_create', $startTime, $endTime]);
        }

        if ($userName != -1) {
            $post->andWhere(['like', 'user_user.user_nickname', '%'.$userName.'%', false]);
        }

        if ($payType != -1) {
            $post->andWhere(['pay_pay.pay_type' => $payType]);
        }

        if ($cityCode != -1) {
            $post->andWhere(['user_user.city_code' => $cityCode]);
        }

        $count = $post->count();
        $result = $post->orderBy('pay_pay.user_id DESC')->limit($limit)->offset($offset)->asArray()->all();

        return ['total'=>$count, 'rows'=>$result];
    }


    //关联用户表 获取用户信息
    public function getUser()
    {
        //同样第一个参数指定关联的子表模型类名
        //第二个参数第一个是字表的 第二个是主表的
        return $this->hasOne(User_user::className(), ['user_id' => 'user_id']);
    }

}